/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.service.transaction.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.grayrabbit.pay.core.dao.transaction.TradeHistoryDao;
import org.grayrabbit.pay.core.model.entity.transaction.TradeHistory;
import org.grayrabbit.pay.core.model.pages.PageList;
import org.grayrabbit.pay.core.model.pages.PageTools;
import org.grayrabbit.pay.core.service.transaction.TradeHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 
 * 
 * @author liyd
 * @version $Id: TradeHistoryServiceImpl.java, v 0.1 Fri Jun 01 11:16:04 CST 2012 liyd Exp $
 */
@Component
public class TradeHistoryServiceImpl implements TradeHistoryService {

    @Autowired
    private TradeHistoryDao tradeHistoryDao;

    /**
     * 查询业务对象列表
     * 
     * @param tradeHistory
     * @return
     */
    public PageList<TradeHistory> queryPageList(TradeHistory tradeHistory) {

        PageTools pageTools = new PageTools();
        pageTools.setPage(tradeHistory.getPageNum());
        pageTools.setItemsPerPage(tradeHistory.getPageSize());

        Map<String, Object> params = new HashMap<String, Object>();

        params.put("query", tradeHistory);
        params.put("startRow", pageTools.getBeginIndex());
        params.put("pageSize", pageTools.getItemsPerPage());

        pageTools.setItems(tradeHistoryDao.queryCount(params));

        PageList<TradeHistory> pageList = new PageList<TradeHistory>();
        pageList.addAll(tradeHistoryDao.queryPageList(params));
        pageList.setPageTools(pageTools);

        return pageList;

    }

    public PageList<TradeHistory> queryPageList(TradeHistory tradeHistory, Date startDate,
                                                Date endDate) {

        PageTools pageTools = new PageTools();
        pageTools.setPage(tradeHistory.getPageNum());
        pageTools.setItemsPerPage(tradeHistory.getPageSize());

        Map<String, Object> params = new HashMap<String, Object>();

        params.put("query", tradeHistory);
        params.put("startRow", pageTools.getBeginIndex());
        params.put("pageSize", pageTools.getItemsPerPage());
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        pageTools.setItems(tradeHistoryDao.queryCount(params));

        PageList<TradeHistory> pageList = new PageList<TradeHistory>();
        pageList.addAll(tradeHistoryDao.queryPageList(params));
        pageList.setPageTools(pageTools);

        return pageList;

    }

    /**
     * 根据Id得到实体对象
     * 
     * @param id
     * @return
     */
    public TradeHistory getById(Long id) {

        return tradeHistoryDao.getById(id);
    }

    /**
     * 根据id批量删除
     * 
     * @param idArray
     */
    public void deleteBatchById(Long[] idArray) {
        tradeHistoryDao.deleteBatchById(idArray);
    }

    
    /**
     * 添加一个对象
     * 
     * @param tradeHistory
     */
    public void insert(TradeHistory tradeHistory) {

        tradeHistoryDao.save(tradeHistory);

    }

    /**
     * 更新一个对象
     * 
     * @param tradeHistory
     * @return
     */
    public int update(TradeHistory tradeHistory) {

        return tradeHistoryDao.update(tradeHistory);

    }

    /**
     * 删除一个对象
     * 
     * @param tradeHistory
     */
    public void delete(TradeHistory tradeHistory) {
        tradeHistoryDao.delete(tradeHistory);
    }

    @Override
    public List<TradeHistory> getBySystemId(Long systemId) {
        // TODO Auto-generated method stub
        return tradeHistoryDao.getBySystemId(systemId);
    }

   
    /**
     * 根据tradeHistory查询历史交易列表
     * 
     * @param tradeHistory
     * @return
     */
    public List<TradeHistory> queryList(TradeHistory tradeHistory) {
        return tradeHistoryDao.queryList(tradeHistory);
    }

}
